Skip to Content
author's profile photo Former Member
Former Member

Itemwise Customer data

hi,

how to get itemwise customer data??..

i had joined vbak and vbap tables and selected data for the entered item range..

later i used for all entries of (vbak and vbap joining) itab to fetch the data from kna1.

is it a correct way??.

thanks

Sri

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 19, 2009 at 09:29 AM

    hi,

    yes it is correct..since kunnr is the key of the kna1 it will fetch the details correctly...

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 19, 2009 at 09:14 AM

    yes its correct

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 19, 2009 at 09:14 AM

    Hi,

    This looks good only. r u not getting the desired values what you are expecting ?

    then let us know the problem.

    Regards,

    Venkatesh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 19, 2009 at 09:16 AM

    Not a problem if you get dat afor all your customers based on your ITAB using

    FOR ALL ENTRIES IN itab

    WHERE kunnr = itab-kunnr...

    Later on to fill your output tab you could READ this kna1_itab and fill details based on customer number..

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      hi,

      this is the code i wrote actually,but i couldnt get output even if there are records in kna1 itab.

      REPORT ZITEM_REPORT line-size 150.

      &----


      *& STRUCTURE DECLARATION

      &----


      types: begin of ty_sale, " Sales document header

      vbeln type vbeln_va, " Sales document

      posnr type posnr_va, " Sales document Item

      netwr type netwr_ak, " Net value

      kunnr type kunnr, " Customer Number

      end of ty_sale,

      begin of ty_kna1,

      kunnr type kunnr, " Customer Number

      land1 type land1_gp, " Country

      name1 type name1_gp, " Customer Name

      ort01 type ort01_gp, " City

      pstlz type pstlz, " Postal Code

      end of ty_kna1,

      begin of ty_output, " Output Structure

      posnr type posnr,va, " Sales document Item

      netwr type netwr_ak, " Net value

      kunnr type kunnr, " Customer Number

      land1 type land1_gp, " Country

      name1 type name1_gp, " Customer Name

      ort01 type ort01_gp, " City

      pstlz type pstlz, " Postal Code

      end of ty_output.

      &----


      *& INTERNAL TABLE DECLARATION

      &----


      data: t_sale type standard table of ty_sale initial size 0,

      t_kna1 type standard table of ty_kna1 initial size 0,

      t_output type standard table of ty_output initial size 0,

      &----


      *& WORK AREA DECLARATION

      &----


      w_sale type ty_sale,

      w_kna1 type ty_kna1,

      w_output type ty_output,

      &----


      *& GLOBAL VARIABLE DECLARATION

      &----


      g_posnr type vbap-posnr.

      &----


      *& SELECTION-SCREEN DECLARATION

      &----


      SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE t001.

      SELECT-OPTIONS: s_posnr for g_posnr.

      SELECTION-SCREEN END OF BLOCK B1.

      &----


      *& INITIALIZATION EVENT

      &----


      initialization.

      clear: w_sale,

      w_kna1,

      w_output.

      refresh: t_sale,

      t_kna1,

      t_output.

      &----


      *& AT SELECTION-SCREEN

      &----


      AT SELECTION-SCREEN.

      perform sub_validate_posnr.

      &----


      *& START-OF-SELECTION EVENT

      &----


      start-of-selection.

      • Get sales document data

      perform sub_get_saledata.

      • Get the Sold-to-party data

      perform sub_get_kna1.

      • Get output data

      perform sub_disp_output.

      &----


      *& Form SUB_VALIDATE_POSNR

      &----


      • SUBROUTINE TO VALIDATE ITEM NUMBER

      ----


      FORM SUB_VALIDATE_POSNR.

      data: l_posnr type posnr_va.

      SELECT SINGLE POSNR

      FROM VBUP

      INTO l_posnr

      where posnr in s_posnr.

      if sy-subrc <> 0.

      message e001(zks) with 'Data not found for the given range' s_posnr.

      endif.

      ENDFORM. " SUB_VALIDATE_POSNR

      &----


      *& Form SUB_GET_SALEDATA

      &----


      • Subroutine to get sales document data

      ----


      FORM SUB_GET_SALEDATA .

      SELECT A~VBELN

      A~POSNR

      B~NETWR

      B~KUNNR

      INTO TABLE T_SALE

      FROM VBAP AS A INNER JOIN VBAK AS B

      ON AVBELN = BVBELN

      WHERE A~POSNR IN S_POSNR.

      IF sy-subrc <> 0.

      message e001(zks) with 'Data not selected in Sales tables' s_posnr.

      endif.

      ENDFORM. " SUB_GET_SALEDATA

      &----


      *& Form SUB_GET_KNA1

      &----


      • SUBROUTINE TO FETCH SOLD-TO-PARTY DATA

      ----


      FORM SUB_GET_KNA1 .

      IF T_SALE IS NOT INITIAL.

      select kunnr

      land1

      name1

      ort01

      pstlz

      from kna1

      into table t_kna1

      for all entries in t_SALE

      where kunnr = t_SALE-kunnr.

      if sy-subrc <> 0.

      message e001(zks) with 'Customer data not selected' s_posnr.

      endif.

      ENDIF.

      ENDFORM. " SUB_GET_KNA1

      &----


      *& Form SUB_DISP_OUTPUT

      &----


      • SUBROUTINE TO DISPLAY OUTPUT

      ----


      FORM SUB_DISP_OUTPUT .

      LOOP AT T_kna1 INTO W_kna1.

      W_OUTPUT-KUNNR = W_kna1-KUNNR.

      W_OUTPUT-LAND1 = W_KNA1-LAND1.

      W_OUTPUT-NAME1 = W_KNA1-NAME1.

      W_OUTPUT-ORT01 = W_KNA1-ORT01.

      W_OUTPUT-PSTLZ = W_KNA1-PSTLZ.

      CLEAR w_sale.

      READ TABLE T_sale INTO W_sale WITH KEY = W_kna1-KUNNR.

      IF SY-SUBRC = 0.

      W_OUTPUT-POSNR = W_SALE-POSNR.

      W_OUTPUT-NETWR = W_SALE-NETWR.

      ENDIF.

      COLLECT w_OUTPUT into t_output.

      ENDLOOP.

      SORT T_OUTPUT BY POSNR KUNNR.

      clear w_output.

      LOOP AT T_OUTPUT INTO W_OUTPUT.

      write:/ w_output-posnr,20 w_output-netwr, 50 w_output-kunnr , 80 w_output-name1,

      120 w_output-land1,130 w_output-pstlz.

      ENDLOOP.

      ENDFORM.

      Edited by: Sri on Jan 19, 2009 10:51 AM

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.