Posted: Sat Oct 27, 2007 3:22 pm Post subject: Loads the Material Assignment of Routings
Okay this is how it works:
When you try to create, you would find a pushbutton 'INSERT NEW LINES' or something simialr to enter your data in the next line. Say you're entering the Material inthe first row, its field position would be MARA-MATNR(01). Now when you click the Insert Pushbitton the cursor always is at positon 2. so you have to loop the remaining data to enter in MARA-MATNR(02). Yougenereally set a counter and pass that counter value (in this case the counter value is 2 always)
The other case when you don't have a push button to Insert. Enter all the rows and then do a Page down. Now your cursor would sit back at position 2 again. Say if there are 20 rows in the first screen. You would keep incrementing the counter and then when it is 21 you do a pagedown and then reset the counter to 2. You loop the pagedown and in it you loop the counter.
I have attached a BDC where I use the second case (no push button). Do a recording and then you would know all the answers by yourself.
Code:
*&---------------------------------------------------------------------*
*& REPORT ZPP0122 *
*&---------------------------------------------------------------------*
*& Module : PP |
*& Application : The program loads the Material Assignment of Routings |
*& |
*&---------------------------------------------------------------------*
REPORT zpp0122 NO STANDARD PAGE HEADING
MESSAGE-ID z0
LINE-SIZE 132
LINE-COUNT 65(2).
SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.
PARAMETERS: p_fname1 TYPE localfile .
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.
PARAMETERS: p_rloc1 AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-005.
PARAMETERS p_group(12) OBLIGATORY DEFAULT 'ZROUTING'.
SELECTION-SCREEN END OF BLOCK c.
SELECTION-SCREEN END OF BLOCK b.
SELECTION-SCREEN END OF BLOCK a.
**WRITE the report header
TOP-OF-PAGE.
INCLUDE zheading.
*----------------------------------------------------------------------*
* Start of selection *
*----------------------------------------------------------------------*
START-OF-SELECTION.
* Load Input file
PERFORM f_load_input_file.
* Create BDC records.
PERFORM create_bdc_records .
*&---------------------------------------------------------------------*
*& Form Create_BDC_records
*&---------------------------------------------------------------------*
* perform the BDC for the records in the internal table
*----------------------------------------------------------------------*
FORM create_bdc_records .
IF NOT i_rout[] IS INITIAL.
** Open BDC session
PERFORM open_bdc_session.
LOOP AT i_rout.
g_my_rec_in = i_rout.
AT NEW plnnr.
CLEAR i_bdc_table[].
PERFORM insert_screen_header.
ENDAT.
CONCATENATE 'MAPL-PLNAL(' g_counter ')' INTO g_field_name.
PERFORM bdc_field USING g_field_name i_rout-plnal.
CONCATENATE 'MAPL-MATNR(' g_counter ')' INTO g_field_name.
PERFORM bdc_field USING g_field_name i_rout-matnr.
CONCATENATE 'MAPL-WERKS(' g_counter ')' INTO g_field_name.
PERFORM bdc_field USING g_field_name i_rout-werks.
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
g_counter = g_counter + 1.
* Page Down for further entries
IF g_counter = 19.
PERFORM bdc_field USING 'BDC_OKCODE' '=P+'.
PERFORM bdc_dynpro USING 'SAPLCZDI' '1010'.
g_counter = 2.
ENDIF.
AT END OF plnnr.
PERFORM bdc_field USING 'BDC_OKCODE' '=BACK'.
PERFORM bdc_dynpro USING 'SAPLCPDI' '1200'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.
PERFORM insert_bdc_new.
ENDAT.
ENDLOOP.
CLEAR i_rout[].
PERFORM close_bdc_session.
** Release the BDC sessions created
PERFORM release_bdc.
ENDIF.
ENDFORM. " open_group
*&---------------------------------------------------------------------*
*& Form bdc_dynpro_start
*&---------------------------------------------------------------------*
* Call the screen for the input of fields
*----------------------------------------------------------------------*
* -->P_G_PROGRAM_1
* -->P_G_SCREEN
*----------------------------------------------------------------------*
FORM bdc_dynpro USING p_g_program_1
p_g_screen.
*&---------------------------------------------------------------------*
*& Form bdc_field
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM bdc_field USING f_name f_value.
* IF f_value <> space.
CLEAR i_bdc_table.
i_bdc_table-fnam = f_name.
i_bdc_table-fval = f_value.
APPEND i_bdc_table.
* ENDIF.
ENDFORM. "bdc_insert_field
*&--------------------------------------------------------------------*
*& Form open_bdc_session
*&--------------------------------------------------------------------*
* Create the BDC session
*---------------------------------------------------------------------*
FORM open_bdc_session .
** Open BDC session and creat and update condition records
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
* DEST = FILLER8
group = p_group
* HOLDDATE = FILLER8
keep = 'X'
user = sy-uname
* RECORD = FILLER1
* PROG = SY-CPROG
* IMPORTING
* QID =
EXCEPTIONS
client_invalid = 1
destination_invalid = 2
group_invalid = 3
group_is_locked = 4
holddate_invalid = 5
internal_error = 6
queue_error = 7
running = 8
system_lock_error = 9
user_invalid = 10
OTHERS = 11
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " create_bdc_session
*&---------------------------------------------------------------------*
*& Form insert_screen_header
*&---------------------------------------------------------------------*
* Header Data inserted
*----------------------------------------------------------------------*
FORM insert_screen_header .
g_counter = 1.
* First screen
PERFORM bdc_dynpro USING 'SAPLCPDI' '1010'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RC271-PLNNR'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ALUE'.
PERFORM bdc_field USING 'RC271-PLNNR' g_my_rec_in-plnnr.
PERFORM bdc_field USING 'RC27M-MATNR' ' '.
PERFORM bdc_field USING 'RC27M-WERKS' ' '.
PERFORM bdc_field USING 'RC271-PLNAL' ' '.
*next screen
PERFORM bdc_dynpro USING 'SAPLCPDI' '1200'.
PERFORM bdc_field USING 'BDC_OKCODE' '=MTUE'.
*next screen
PERFORM bdc_dynpro USING 'SAPLCZDI' '1010'.
ENDFORM. " insert_screen_header
*&---------------------------------------------------------------------*
*& Form insert_bdc
*&---------------------------------------------------------------------*
* Insert the BDC for the transaction
*----------------------------------------------------------------------*
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CLEAR i_bdc_table[].
ENDFORM. " insert_bdc
*&---------------------------------------------------------------------*
*& Form close_bdc_session
*&---------------------------------------------------------------------*
* Close the session
*----------------------------------------------------------------------*
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " close_bdc_session
*&---------------------------------------------------------------------*
*& Form f_load_input_file
*&---------------------------------------------------------------------*
* Load the data file
*----------------------------------------------------------------------*
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 cannot 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.