Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

looing the header data and item data based on posting key

former_member612655
Participant
0 Kudos

Hi,

how to do looping for header data and item data for bdc

i attached my excel file for that file i want to upload into sap system through bdc .

But can you please help me to find out what are header data and item data in that excel file and how to loop the header data as well as item data based on posting key

6 REPLIES 6

venkateswaran_k
Active Contributor
0 Kudos

Hi Bhavani,

I remember you had similar BDC issues you raised couple of weeks before. Is this the same issue or different.

I would suggest BAPI instead of BDC - which will be convenient to handle.

Please update

Let me know if you need any help on BAPI - I can provide you with model template

Abinathsiva
Active Contributor
0 Kudos

Hi bhavani123,

Add one more column in excel and mention H and L as a indicator, load to respective Internal Table and proceed.

Regards

Abinath. S

Sandra_Rossi
Active Contributor
0 Kudos

I can't understand your question at all. You don't even tell what transaction you call.

If you want people to create the program for you (for free), please provide the specification. Crystal balls don't work with programming.

former_member612655
Participant
0 Kudos

Hi Krishnamurty Sir,

As you said that can you please provide model template for bapi

venkateswaran_k
Active Contributor
0 Kudos

Dear Bhavani,

I would suggest you to go for the BAPI. Use the following steps and code - which is working code for me. You adjust it according to your dataset.

Step 1 : Declare Data

DATA : header         TYPE bapiache09,
       customer       TYPE bapiacpa09,
       docno          TYPE bapiache09-obj_key,
       accountgl      TYPE STANDARD TABLE OF bapiacgl09 WITH HEADER LINE,
       accountar      TYPE STANDARD TABLE OF bapiacar09 WITH HEADER LINE,
       currencyamount TYPE STANDARD TABLE OF bapiaccr09 WITH HEADER LINE,
       taxline        TYPE STANDARD TABLE OF BAPIACTX09 WITH HEADER LINE,
       return         TYPE STANDARD TABLE OF bapiret2   WITH HEADER LINE,
       creditcard     TYPE STANDARD TABLE OF bapiacpc09 WITH HEADER LINE,
       msg            TYPE c LENGTH 50.

You may arrange and  call like this....
PERFORM debit_entry_cc.
PERFORM credit_entry_cc.
PERFORM bapi_gl_posting_cc.

Step 2 : Populate Debit Items

FORM debit_entry_cc .
  DATA lin TYPE int4.
  DATA saknr TYPE ska1-saknr.
  dr = 0.
  LOOP AT it_finalposting_cc INTO wa_finalposting_cc.
    IF wa_finalposting_cc-bschl = '40'.
      lin = lin + 1.
      accountgl-itemno_acc = <item number> "here it goes like 10,20,30 etc
      saknr = wa_finalposting_cc-hkont.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = saknr
        IMPORTING
          output = saknr.
      accountgl-gl_account =  saknr.
      accountgl-comp_code = '1000'.
      accountgl-pstng_date = sy-datum.
      accountgl-doc_type = <your documen ttype>
      accountgl-item_text =  <your text>
      accountgl-alloc_nmbr = wa_finalposting_cc-zuonr .
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = wa_finalposting_cc-kostl
        IMPORTING
          output = wa_finalposting_cc-kostl.
      accountgl-costcenter = wa_finalposting_cc-kostl.
      APPEND accountgl.
    currencyamount-itemno_acc = <item number> " same item number you mentioned above
      currencyamount-currency = 'SAR'.
      currencyamount-amt_doccur = wa_finalposting_cc-debit.
      APPEND currencyamount.
      dr = dr + wa_finalposting_cc-debit.
      CLEAR : currencyamount, accountgl.
    ENDIF.
    CLEAR : currencyamount, accountgl, wa_finalposting_cc.
  ENDLOOP.
ENDFORM.

Step 3 : Populate Credit items

FORM credit_entry_cc .
  DATA lin TYPE int4.
  DATA saknr TYPE ska1-saknr.
  cr = 0.


  LOOP AT it_finalposting_cc INTO wa_finalposting_cc.
    IF wa_finalposting_cc-bschl = '50'.
      accountgl-itemno_acc = <item number>  "importnt cr
      saknr = wa_finalposting_cc-hkont.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = saknr
        IMPORTING
          output = saknr.
      accountgl-gl_account =  saknr.
      accountgl-comp_code = '1000'.
      accountgl-pstng_date = sy-datum.
      accountgl-doc_type = <your documen ttype >.
      accountgl-item_text = wa_finalposting_cc-sgtxt .   
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = wa_finalposting_cc-kostl
        IMPORTING
          output = wa_finalposting_cc-kostl.
      accountgl-costcenter = wa_finalposting_cc-kostl.
      accountgl-alloc_nmbr = wa_finalposting_cc-zuonr .
      APPEND accountgl.
      currencyamount-itemno_acc = <item number> " same item mentioned above importatnt cr
      currencyamount-currency = 'SAR'.
      "since credit items - multiply by -1
      currencyamount-amt_doccur = wa_finalposting_cc-credit * -1.
      APPEND currencyamount.
      cr = cr + wa_finalposting_cc-credit.
      CLEAR : currencyamount, accountgl.
    ENDIF.
    CLEAR : currencyamount, accountgl, wa_finalposting_cc.
  ENDLOOP.
ENDFORM.

Step 4 : Call BAPI

FORM bapi_gl_posting_cc .
  header-username = sy-uname.
  header-header_txt = 'Payroll Posting'.
  header-comp_code = '1000'.
  header-doc_date = sy-datum
  header-pstng_date = sy-datum
  header-doc_type = <your document type goes here>.
  header-ref_doc_no = '1'.                  
                " 
  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
      documentheader = header
    IMPORTING
*     OBJ_TYPE       =
      obj_key        = docno
*     OBJ_SYS        =
    TABLES
      accountgl      = accountgl
*     ACCOUNTTAX     = taxline
      currencyamount = currencyamount
*     CRITERIA       =
*     VALUEFIELD     =
*     EXTENSION1     =
      return         = return.

  IF docno IS NOT INITIAL AND docno NE '$'.
    CONCATENATE 'Document ' docno+0(10) 'Created' INTO msg SEPARATED BY space.
    MESSAGE msg TYPE 'S' DISPLAY LIKE 'I'.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
  ELSE.
    MESSAGE 'Please Refer to Final Posting Tab..!' TYPE 'S' DISPLAY LIKE 'S'.
  ENDIF.
ENDFORM.

0 Kudos

Hi

Is your problem resolved? Did you try using the BAPI ?