SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Convert any online transaction-run to a batch input program



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Batch Input (BDC), Background processing and Jobs
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sun Nov 18, 2007 8:44 pm    Post subject: Convert any online transaction-run to a batch input program Reply with quote

Code:
REPORT ZTRBCHIP.
************************************************************************
* This program converts an online transaction run to a batch input
* program. The input parameters are the transaction code and the output
* program name (has to be in the customer name range)
* First the program runs the transaction as normal, and records all the
* screens, fields, input data in the CATT tables. The user has to leave
* the transaction at the end with the green arrow completely. Then, from
* the data in the CATT tables the program creates the source code of the
* batch input program and saves it with the specified name. Later this
* code can be further enhanced.
************************************************************************
TABLES: TSTC.
TABLES: CATF, CATR, CATG, CATV, CATU, CATP, CATX, CATA.

PARAMETERS: TR_CODE LIKE TSTC-TCODE OBLIGATORY DEFAULT 'SU01',
            PR_NAME(8) OBLIGATORY DEFAULT 'ZTTTEEE'.

DATA: TRNAM LIKE CATF-TCODE, ABLNR LIKE CATF-ABLNR,
      FIRST(2), SECOND(2), FNAM(30), FVAL(50), I TYPE I.
DATA: BEGIN OF PROGRAM OCCURS 50,
      LINE(72),
END OF PROGRAM.

* Call the transaction and create the CATT data
CALL FUNCTION 'RS_CATT_MAINTAIN'
     EXPORTING
          AKTION       = 'GENR'
          CONFIRMATION = ' '
          TCODE        = TR_CODE
     IMPORTING
          ABLNR        = ABLNR.

* Create the program source of the bdc creator program
PROGRAM = 'PROGRAM         .'. PROGRAM+8(8) = PR_NAME.   APPEND PROGRAM.
PROGRAM = ' '.                                           APPEND PROGRAM.
PROGRAM = 'data: begin of bdc_tab occurs 100.'.          APPEND PROGRAM.
PROGRAM = '        include structure bdcdata.'.          APPEND PROGRAM.
PROGRAM = 'data: end of bdc_tab.'.                       APPEND PROGRAM.
PROGRAM = ' '.                                           APPEND PROGRAM.
*
SELECT * FROM CATF WHERE ABLNR = ABLNR.
  IF NOT CATF-TCODE IS INITIAL.
    TRNAM = CATF-TCODE.
  ENDIF.
*
  PROGRAM =  'PERFORM BDC_FILL USING ''X'''.
  APPEND PROGRAM.
*
  PROGRAM =  '     '''.  PROGRAM+6 = CATF-MPOOL.
  I = STRLEN( PROGRAM ). PROGRAM+I = ''''.
  APPEND PROGRAM.
*
  PROGRAM =  '     '''.  PROGRAM+6 = CATF-DYNNR.
  I = STRLEN( PROGRAM ). PROGRAM+I = '''.'.
  APPEND PROGRAM.
*
  DO.
    FIRST = CATF-VARF1.
    SHIFT CATF-VARF1 LEFT BY 2 PLACES.
    SECOND = CATF-VARF1.
    SHIFT CATF-VARF1 LEFT BY 2 PLACES.
    IF FIRST IS INITIAL.EXIT. ENDIF.
    FNAM = CATF-VARF1(FIRST).
    SHIFT CATF-VARF1 LEFT BY FIRST PLACES.
    FVAL = CATF-VARF1(SECOND).
    SHIFT CATF-VARF1 LEFT BY SECOND PLACES.
*
    PROGRAM =  'PERFORM BDC_FILL USING '' '''.
    APPEND PROGRAM.
*
    PROGRAM =  '     '''.  PROGRAM+6 = FNAM.
    I = STRLEN( PROGRAM ). PROGRAM+I = ''''.
    APPEND PROGRAM.
*
    PROGRAM =  '     '''.
    IF FVAL = ''' '''.
    I = STRLEN( PROGRAM ). PROGRAM+I = '''.'.
    ELSE.
    PROGRAM+6 = FVAL.
    I = STRLEN( PROGRAM ). PROGRAM+I = '''.'.
    ENDIF.
    APPEND PROGRAM.
*
  ENDDO.
ENDSELECT.
*
PROGRAM = ' '.                                           APPEND PROGRAM.
PROGRAM = 'call transaction '''.PROGRAM+18 = TR_CODE.
I = STRLEN( PROGRAM ). PROGRAM+I = ''''.                 APPEND PROGRAM.
PROGRAM = 'using bdc_tab mode ''N''.'.                   APPEND PROGRAM.
PROGRAM = 'if sy-subrc = 0.'.                            APPEND PROGRAM.
PROGRAM = '   write: / ''ok''.'.                         APPEND PROGRAM.
PROGRAM = 'else.'.                                       APPEND PROGRAM.
PROGRAM = '   write: / ''error''.'.                      APPEND PROGRAM.
PROGRAM = 'endif.'.                                      APPEND PROGRAM.
PROGRAM = ' '.                                           APPEND PROGRAM.
*
PROGRAM = ' '.                                           APPEND PROGRAM.
PROGRAM = 'FORM BDC_FILL USING P1 P2 P3.'.               APPEND PROGRAM.
PROGRAM = '  clear bdc_tab.'.                            APPEND PROGRAM.
PROGRAM = '  if p1 = ''X''.'.                            APPEND PROGRAM.
PROGRAM = '    bdc_tab-dynbegin = p1.'.                  APPEND PROGRAM.
PROGRAM = '    bdc_tab-program = p2.'.                   APPEND PROGRAM.
PROGRAM = '    bdc_tab-dynpro =  p3.'.                   APPEND PROGRAM.
PROGRAM = '  else.'.                                     APPEND PROGRAM.
PROGRAM = '    bdc_tab-dynbegin = p1.'.                  APPEND PROGRAM.
PROGRAM = '    bdc_tab-fnam = p2.'.                      APPEND PROGRAM.
PROGRAM = '    bdc_tab-fval = p3.'.                      APPEND PROGRAM.
PROGRAM = '  endif.'.                                    APPEND PROGRAM.
PROGRAM = '  append bdc_tab.'.                           APPEND PROGRAM.
PROGRAM = 'ENDFORM.'.                                    APPEND PROGRAM.

* Clean the CATT tables
DELETE FROM CATF WHERE ABLNR = ABLNR.
DELETE FROM CATR WHERE ABLNR = ABLNR.
DELETE FROM CATG WHERE ABLNR = ABLNR.
DELETE FROM CATV WHERE ABLNR = ABLNR.
DELETE FROM CATU WHERE ABLNR = ABLNR.
DELETE FROM CATP WHERE ABLNR = ABLNR.
DELETE FROM CATX WHERE ABLNR = ABLNR.
DELETE FROM CATA WHERE ABLNR = ABLNR.
COMMIT WORK.

* Insert the program
INSERT REPORT PR_NAME FROM PROGRAM.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Batch Input (BDC), Background processing and Jobs All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.