Application Development and Automation 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: 
Read only

First ABAP function, beginer help with function module.

Former Member
0 Likes
1,022

Hello experts,

I am very green when it comes to ABAP, I am very new to coding period, so what I have may be completely wrong. That is why I am coming to you guys. I have been assigned to create a function module that returns a list of warehouse codes for finished goods, sorted by city and state. I am required to use multiple tables to complete this, specifically T300,MLGN,MARA,V_T320,T001W.  I am using select statements, and inner joins to retreive the data however when I execute, I am not retrieving any data. If possible I would appreciate any input on my code, or any improvements that could be made.

   TABLES: v_t320,t300,t001w,mlgn,mara.

  TYPES: BEGIN OF lty_lgnum,
          lgnum TYPE lgnum,
        END OF lty_lgnum.
  DATA: lt_lgnum TYPE STANDARD TABLE OF lty_lgnum.

  SELECT: t300~lgnum
    INTO TABLE lt_lgnum FROM
    t300 INNER JOIN mlgn ON t300~lgnum = mlgn~lgnum
         INNER JOIN mara ON mlgn~matnr = mara~matnr
        WHERE mara~mtart = 'ZFIN'                "grab only finished goods?"
        AND t300~regkz = i_regkz.
  IF sy-subrc EQ 0.
    SORT lt_lgnum BY lgnum.
    DELETE ADJACENT DUPLICATES FROM lt_lgnum COMPARING lgnum.
    IF lt_lgnum IS NOT INITIAL.
      SELECT: t320~lgnum                         "warehouse number/ warehouse complex"
              t300t~lnumt                        "warehouse number description"
              t001w~ort01                        "city"
              t001w~regio                        "region"
*          T001W~counc
*          T001W~werks
         FROM t320
        INNER JOIN t001w
           ON t320~werks = t001w~werks
        INNER JOIN t300t
          ON t300t~lgnum EQ  t320~lgnum
        INTO TABLE o_t_wh_details
        FOR ALL ENTRIES IN lt_lgnum
        WHERE t320~lgnum EQ lt_lgnum-lgnum
        .
    ENDIF.
    IF sy-subrc NE 0.
      CALL FUNCTION 'BALW_BAPIRETURN_GET2'
        EXPORTING
          type   = 'E'
          cl     = 'ZPTP'
          number = 031
        IMPORTING
          return = return.
      APPEND return TO return.
      RETURN.
    ENDIF.
  ENDIF.
ENDFUNCTION.

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
938

Hi Jon,

I do not share the opinions already posted.

If you start using JOIN early, you will get used to write very efficient and fast code.

If you do not get any  results, then first look at the table contents of all tables involved in your selection and try to do the joining manually. In most cases this helped me to find an error.

Let me recommend to always use an INTO CORRESPONDING FIELDS OF TABLE in the selection. It is an urban legend that it decreases performance. It does not cost any performance at all.  It makes programming a lot more flexible.

It is a good idea to use standard function BALW_BAPIRETURN_GET2 to populate your return table.

You can enhance transparency and make support people happy usin the MESSAGE .. INTO clause:

data lv_string type string.

MESSAGE e031(ZPTP) into lv_string.

* <message text>


CALL FUNCTION 'BALW_BAPIRETURN_GET2'
        EXPORTING
          type   = sy-msgty
          cl     =
sy-msgid

          number = sy-msgno

This allows people debugging the code to see the message as it is output. Also, you get a where-used-list for this message. If the message is displayed, you can find the code where it was issued.

Happy ABAPing!

Regards

Clemens

6 REPLIES 6
Read only

FredericGirod
Active Contributor
0 Likes
938

Hi,

if you are a beginner stop using INNER JOIN, you will see easily in debug where your SELECT is not good. Here it's a big melting pot of tables ... not readable, not debuggable ..

regards

Fred

Read only

Former Member
0 Likes
938

Hi

Read only

0 Likes
938

Simple question - why?

Read only

Clemenss
Active Contributor
0 Likes
939

Hi Jon,

I do not share the opinions already posted.

If you start using JOIN early, you will get used to write very efficient and fast code.

If you do not get any  results, then first look at the table contents of all tables involved in your selection and try to do the joining manually. In most cases this helped me to find an error.

Let me recommend to always use an INTO CORRESPONDING FIELDS OF TABLE in the selection. It is an urban legend that it decreases performance. It does not cost any performance at all.  It makes programming a lot more flexible.

It is a good idea to use standard function BALW_BAPIRETURN_GET2 to populate your return table.

You can enhance transparency and make support people happy usin the MESSAGE .. INTO clause:

data lv_string type string.

MESSAGE e031(ZPTP) into lv_string.

* <message text>


CALL FUNCTION 'BALW_BAPIRETURN_GET2'
        EXPORTING
          type   = sy-msgty
          cl     =
sy-msgid

          number = sy-msgno

This allows people debugging the code to see the message as it is output. Also, you get a where-used-list for this message. If the message is displayed, you can find the code where it was issued.

Happy ABAPing!

Regards

Clemens

Read only

Former Member
0 Likes
938

Hi,

are you sure you are using the correct input data? Please check whether the i_regkz field contains valid input? I ask, because it really looks fine. Look in table T646R for a list of valid values and then check whether the value you selected actually exists in T300. Then you can check whether there is an entry for your selected magazine in MLGN and then whether any material in that table has the mtart value you hard coded in your function.

Regards,

Roy van de Kerkhof

Read only

Former Member
0 Likes
938

Thank you for all of the input! I was able to complete the function, and retrieve the data that was needed. I will take the suggestions you all made and apply them to my future experiences in the ABAP world. Hopefully this will lead to many more years and knolwdege of ABAP coding for myself.


Thank you again,

Jon Foster