<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to follow best coding practices and make this code runable. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-follow-best-coding-practices-and-make-this-code-runable/m-p/4755326#M1115278</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lets first start from your Select Statement.....Replace your SELECT ....ENDSELECT by SELECT Into Internal Table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your program is having a SELECT...ENDSELECT within LOOP...ENDLOOP........One should avoid doing this as far as possible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT  mkpf~mblnr&lt;/P&gt;&lt;P&gt;              mkpf~xblnr&lt;/P&gt;&lt;P&gt;INTO itab&lt;/P&gt;&lt;P&gt;for all entires i_list&lt;/P&gt;&lt;P&gt;from    mkpf inner join mseg&lt;/P&gt;&lt;P&gt;    on   mkpf&lt;SUB&gt;mandt = mseg&lt;/SUB&gt;mandt&lt;/P&gt;&lt;P&gt;    and mkpf&lt;SUB&gt;mblnr = mseg&lt;/SUB&gt;mblnr&lt;/P&gt;&lt;P&gt;    and mkpf&lt;SUB&gt;mjahr = mseg&lt;/SUB&gt;mjahr&lt;/P&gt;&lt;P&gt;    where mseg~matnr = i_list-matnr&lt;/P&gt;&lt;P&gt;       and mseg~charg = i_list-charg&lt;/P&gt;&lt;P&gt;       and mseg~kunnr = i_list-kunnr&lt;/P&gt;&lt;P&gt;       and mseg~sobkz = i_list-sobkz&lt;/P&gt;&lt;P&gt;       and mseg~werks = i_list-werks&lt;/P&gt;&lt;P&gt;       and mkpf~budat in budat.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Restructure youe complete code with this approach and Share your Finding's. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also think of using a SAP Standard FM.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway..What is the objective/Output of this report?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 09 Nov 2008 15:02:58 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-11-09T15:02:58Z</dc:date>
    <item>
      <title>how to follow best coding practices and make this code runable.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-follow-best-coding-practices-and-make-this-code-runable/m-p/4755325#M1115277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How to change this code to make it work and follow best coding practices.&lt;/P&gt;&lt;P&gt;This code is to add fields to internal table LIST which already exist.&lt;/P&gt;&lt;P&gt;In the loop are all the selections which are to be made.&lt;/P&gt;&lt;P&gt;But i am new to ABAP and not sure how to make this work.&lt;/P&gt;&lt;P&gt;please help me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: wa_list LIKE LINE OF list,
      l_v_index TYPE i.
DATA: t_price_result1 TYPE STANDARD TABLE OF komv WITH HEADER LINE INITIAL SIZE 0.
DATA: wa_result LIKE LINE OF t_price_result1.

LOOP AT list INTO wa_list.

  l_v_index = sy-tabix.

*GET MATERIAL DOCUMENT(MBLNR) AND DELIVERY NUMBER(XBLNR)

  SELECT  mkpf~mblnr
          mkpf~xblnr
   into (wa_list-mblnr, wa_list-xblnr )
*            INTO i_list
   from mkpf inner join mseg
*   up to 1 rows
    on mkpf~mandt = mseg~mandt
    and mkpf~mblnr = mseg~mblnr
    and mkpf~mjahr = mseg~mjahr
    where mseg~matnr = wa_list-matnr
     and mseg~charg = wa_list-charg
     and mseg~kunnr = wa_list-kunnr
     and mseg~sobkz = wa_list-sobkz
     and mseg~werks = wa_list-werks
     and mkpf~budat in budat.
                                                            "RFC3762
  ENDSELECT.

  wa_list-mblnr = list-mblnr.
  wa_list-xblnr = list-xblnr.


* GET POSNR FROM TABLE LIPS
  SELECT posnr
  FROM lips
  INTO list-posnr
  up to 1 rows
  WHERE vbeln = wa_list-xblnr AND
             matnr = wa_list-matnr.
  ENDSELECT.

  wa_list-posnr = list-posnr.

* GET SALES ORDER #
  SELECT vbelv
  FROM vbfa
  INTO list-vbelv
  up to 1 rows
*        INTO wa_list
  WHERE vbeln =  wa_list-xblnr.
  ENDSELECT.
  wa_list-vbelv = list-vbelv.
*GET PO
  SELECT bstkd
  FROM vbkd
  INTO list-bstkd
  up to 1 rows
  WHERE vbeln =  wa_list-vbelv
      AND posnr = 0.
  ENDSELECT.

  wa_list-bstkd = list-bstkd.
*get serial number
  SELECT SINGLE obknr
   FROM ser01
   INTO list-obknr

   WHERE lief_nr = wa_list-xblnr
       AND posnr = wa_list-posnr.

wa_list-obknr = list-obknr.

SELECT sernr
FROM objk
INTO list-sernr
up to 1 rows
WHERE obknr = wa_list-obknr.
ENDSELECT.
wa_list-sernr = wa_list-sernr.

*get date
SELECT budat FROM mkpf
INTO list-budat
up to 1 rows
 where mblnr = wa_list-mblnr.
ENDSELECT.

wa_list-budat = list-budat.

*get CLP
SELECT   vkorg vtweg spart
INTO (list-vkorg, list-vtweg, list-spart)
up to 1 rows
FROM vbak WHERE vbeln = wa_list-vbelv.
ENDSELECT.

wa_list-vkorg = list-vkorg.
wa_list-vtweg = list-vtweg.
wa_list-spart = list-spart.


SELECT pstyv
INTO list-pstyv
FROM  vbap
up to 1 rows
 WHERE vbeln = wa_list-vbelv AND posnr = wa_list-posnr.
ENDSELECT.
wa_list-pstyv = list-pstyv.


CALL FUNCTION 'Z_SD_PRICING_CONDITION'
EXPORTING
i_organization                  = wa_list-vkorg
i_dist_channel                  = wa_list-vtweg
i_division                      = wa_list-spart
i_customer                      = wa_list-kunnr
i_plant                         = wa_list-werks
*      i_pricng_date                   = sy-datum
i_material                      = wa_list-matnr
*   I_SALES_UNIT                    = 'EA'
*   I_QUANTITY                      = '1.000'
i_stor_loc                      = '0001'
i_item_cat                      = 'TAN'
*   I_AUART                         =
*   I_REFRESH                       = 'X'
*   I_KOMP                          =
*   I_KOMK                          =
* IMPORTING
*   E_MES_TYPE                      =
*   E_MES_NUMBER
*   E_MESSAGE                       =

TABLES
t_price_result                  = t_price_result1
* EXCEPTIONS
*   CUSTOMER_NOT_FOUND              = 1
*   PLANT_NOT_FOUND                 = 2
*   MATERIAL_NOT_FOUND              = 3
**   PLANT_MATERIAL_NOT_FOUND       = 4
*   SALES_DATA_NOT_FOUND            = 5
*   ORG_UNIT_NOT_FOUND              = 6
*   UNABLE_TO_CALCULATE_PRICE       = 7
*   UNABLE_TO_FORMAT_PRICE          = 8
*   MANDATORY_INFOR_MISSING         = 9
*   OTHERS                          = 10
.

LOOP AT t_price_result1.
  IF  t_price_result1-kschl = 'ZPR2'.
    wa_list-kbetr = t_price_result1-kbetr.
  ELSE.
    wa_list-kbetr = 0.
  ENDIF.
ENDLOOP.
MODIFY list FROM wa_list INDEX l_v_index.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Nov 2008 13:46:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-follow-best-coding-practices-and-make-this-code-runable/m-p/4755325#M1115277</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-11-09T13:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to follow best coding practices and make this code runable.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-follow-best-coding-practices-and-make-this-code-runable/m-p/4755326#M1115278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lets first start from your Select Statement.....Replace your SELECT ....ENDSELECT by SELECT Into Internal Table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your program is having a SELECT...ENDSELECT within LOOP...ENDLOOP........One should avoid doing this as far as possible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT  mkpf~mblnr&lt;/P&gt;&lt;P&gt;              mkpf~xblnr&lt;/P&gt;&lt;P&gt;INTO itab&lt;/P&gt;&lt;P&gt;for all entires i_list&lt;/P&gt;&lt;P&gt;from    mkpf inner join mseg&lt;/P&gt;&lt;P&gt;    on   mkpf&lt;SUB&gt;mandt = mseg&lt;/SUB&gt;mandt&lt;/P&gt;&lt;P&gt;    and mkpf&lt;SUB&gt;mblnr = mseg&lt;/SUB&gt;mblnr&lt;/P&gt;&lt;P&gt;    and mkpf&lt;SUB&gt;mjahr = mseg&lt;/SUB&gt;mjahr&lt;/P&gt;&lt;P&gt;    where mseg~matnr = i_list-matnr&lt;/P&gt;&lt;P&gt;       and mseg~charg = i_list-charg&lt;/P&gt;&lt;P&gt;       and mseg~kunnr = i_list-kunnr&lt;/P&gt;&lt;P&gt;       and mseg~sobkz = i_list-sobkz&lt;/P&gt;&lt;P&gt;       and mseg~werks = i_list-werks&lt;/P&gt;&lt;P&gt;       and mkpf~budat in budat.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Restructure youe complete code with this approach and Share your Finding's. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also think of using a SAP Standard FM.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway..What is the objective/Output of this report?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Nov 2008 15:02:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-follow-best-coding-practices-and-make-this-code-runable/m-p/4755326#M1115278</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-11-09T15:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to follow best coding practices and make this code runable.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-follow-best-coding-practices-and-make-this-code-runable/m-p/4755327#M1115279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Pinjo,&lt;/P&gt;&lt;P&gt;Here is the restructured code for you.&lt;/P&gt;&lt;P&gt;Few points you need to keepin mind.&lt;/P&gt;&lt;P&gt;1. Do not your SELECT ENDSELECT. It degrade your performance. Instead of this use Select query and populate it in into internal table.&lt;/P&gt;&lt;P&gt;2. do not use Select query inside Loop Endloop instead of this you can use FOR ALL ENTRIES IN statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Chidanand&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Nov 2008 17:10:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-follow-best-coding-practices-and-make-this-code-runable/m-p/4755327#M1115279</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-11-09T17:10:23Z</dc:date>
    </item>
  </channel>
</rss>

